<?php
require_once "globalFunctions.php";
// Upload a file and create a database record.
ini_set('file_uploads', 'On');
$file = $_FILES['file']['name'];
$ext = pathinfo($file, PATHINFO_EXTENSION);
if ($_POST["name"] && $_POST["desc"] && $_POST["tags"]) {
	$targetdir = __DIR__ . "/../content/uploads/";
	$target = md5(mt_rand()) . "." . $ext;
	if (move_uploaded_file($_FILES["file"]["tmp_name"], ($targetdir . $target)) && $_FILES['file']['size'] < 2560000 && in_array($ext, array("PNG","JPG","GIF","JPEG","png","jpg","gif","jpeg"))) {
		getDB()->AddImage($_POST["name"], $_POST["desc"], $target, 1, $_POST["tags"]);
		echo "done";
	} else {
		echo "invalid upload";
	}
}
?>